<?php
class Category extends AppModel {

	var $name = 'Category';
	var $validate = array(
		'name' => array('notempty')		
	);

	//The Associations below have been created with all possible keys, those that are not needed can be removed
	var $hasMany = array(
			'News' => array('className' => 'News',
								'foreignKey' => 'category_id',
								'dependent' => false,
								'conditions' => '',
								'fields' => '',
								'order' => '',
								'limit' => '',
								'offset' => '',
								'exclusive' => '',
								'finderQuery' => '',
								'counterQuery' => ''
			),
			'Product' => array('className' => 'Product',
								'foreignKey' => 'category_id',
								'dependent' => false,
								'conditions' => '',
								'fields' => '',
								'order' => '',
								'limit' => '',
								'offset' => '',
								'exclusive' => '',
								'finderQuery' => '',
								'counterQuery' => ''
			)
	);
	
	function findOrderList($condition = null) {
		// array to build list categories
		$return = array ( );
		// find all categories order by root_path
		$this->Category->recursive = 0;		
		$categories = $this->Category->findAll ($condition, null, 'root_path' );
		foreach ( $categories as $category ) {
			$temp = "";
			$spaceAlowLevel = str_repeat('-', $category['Category']['level']-1);
			$temp .= $spaceAlowLevel.$category ['Category'] ['name'];				
			$return [$category ['Category'] ['id']] = $temp;
		}
		return $return;
	}
}
?>